<template>
    <vol-box :lazy="true" v-model="model" title="选择工序" :width="1200" :padding="0">
        <div>
            <productProcess ref="productProcessRef"></productProcess>
        </div>
        <template #footer>
            <div> <el-button type="primary" @click="onSelect">确认</el-button></div>
        </template>
    </vol-box>
</template>
<script setup>
import { ref, getCurrentInstance, nextTick } from 'vue'
const { proxy } = getCurrentInstance();

import productProcess from '@/views/mes/mes/ProductProcess.vue';
//注意：1. '@/views/mes/mes/MES_Customer.vue'改为想要选择的vue文件
//2.在MES_Customer.vue的onInit中应该重新设置表格高度,代码实现如下：
// const onInited = async () => {
//     //判断当前页面路由地址是不是选择的数据地址
//     if (proxy.$route.path=='/MES_ProductionOrder') {
//          //设置表格高度
//          gridRef.height=350;
//          //设置为单选
//          gridRef.single=true;
//     }
// }

const productProcessRef = ref();
const model = ref(false)
const detailRow = ref({})
//回调
const emit = defineEmits('onSelectProductProcess')
const open = (row) => {
    //打开主表选择数据
    detailRow.value = row;

    model.value = true;
    //打开时刷新界面数据
    nextTick(() => { productProcessRef.value?.$refs.grid?.search() });
}
//选择数据
const onSelect = () => {
    //主表的选择数据回写到主表的表单上
    let rows = productProcessRef.value.$refs.grid.getSelectRows();
    if (!rows.length) {
        return proxy.$message.error('请选择数据');
    }

    if (detailRow.value) {
        detailRow.value.ProductProcessId = rows[0].ProductProcessId;
        detailRow.value.ProcessCode = rows[0].Code;
        detailRow.value.ProcessName = rows[0].Name;
        detailRow.value.DepartmentId = rows[0].DepartmentId;
        detailRow.value.DeviceId = rows[0].DeviceId;
        detailRow.value.GroupId = rows[0].GroupId;
        detailRow.value.ProcessTypeId = rows[0].ProcessTypeId;
        detailRow.value.WorkHourPrice = rows[0].WorkHourPrice;
        detailRow.value.WorkQtyPrice = rows[0].WorkQtyPrice;
        detailRow.value.PriceTypeId = rows[0].PriceTypeId;
        detailRow.value.IsLasted = 0;

        emit('onSelectProductProcess', rows)
    }
    model.value = false;


}
//暴露选择弹出框方法
defineExpose({ open })
</script>
<style lang="less" scoped>
.search-form {
    display: flex;
    padding: 10px;
    line-height: 34px;

    button {
        margin-left: 10px;
    }
}
</style>